//
//  FontViewController.m
//  WDFans
//
//  Created by Zhihong Yuan on 3/28/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FontViewController.h"
#import "UIFont+Utilities.h"

@interface FontViewController()

@property (nonatomic, retain) IBOutlet NSArray *properties;

@end

@implementation FontViewController

@synthesize myTableView;
@synthesize properties;

#pragma mark - View lifecycle
- (void)dealloc
{
    [properties release];
    [myTableView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"正文字体";
    [self setBackgroundImageViewForTabView];
    self.properties = [NSArray arrayWithObjects:@"大",@"中",@"小", nil];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.myTableView = nil;
    self.properties = nil;
}

#pragma mark - UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.properties count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentify = @"cellIdentify";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if(nil == cell)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify] autorelease];
        cell.textLabel.textColor = [UIColor cellLeftKeyTextColor];
        cell.textLabel.font = [UIFont getSettingViewTableCellLabelFont];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.textLabel.text = [self.properties objectAtIndex:indexPath.row];
    NSString *font = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:kFontKey];
    if([font isEqualToString:cell.textLabel.text])
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    return cell;
}
#pragma mark - UITableViewDelegate methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSArray *cells = [tableView visibleCells];
    for(UITableViewCell *cell in cells)
        cell.accessoryType = UITableViewCellAccessoryNone;
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [[NSUserDefaults standardUserDefaults] setObject:[self.properties objectAtIndex:indexPath.row] forKey:kFontKey];
}

@end
